
<script >







import storage from "./../utils/storage";

export default {
  name: 'Weather',
  data () {
    return {
      address: "北京",
      list: [],
      indexList: []


    }
  },
  mounted () {
    this.getWeatherIndex()

  },
  methods: {

    async getWeatherIndex () {

     
      try {

        

      

        if(storage.getItem("indexList").length>0){
        this.list = storage.getItem("indexList")
      }else{
        this.list = await this.$api.weatherIndex(this.address)
        console.log(this.list)
      }


   
   

      
      } catch (error) {
        console.log(error)
      }
    },


  }

}

</script>

<template>
  <main>

    <div class="container" ref="card" v-for="item in list" >

      <header class="head">

        <div class="left" >
          <div class="text">当前位置：{{ item.name }}</div>

          <el-input class="input" v-model="address" placeholder="Please input" suffix-icon="el-icon-date" size="large" />

        </div>

        <el-button class="mr10" type="success" @click="getWeatherIndex()">搜索</el-button>
      </header>

      <div class="main">
        <div class="box1">
          <div>温度{{item.temp  }}</div>
          <div> 时间{{ item.uptime }}
            <div></div>

          </div>
        </div>
        <div class="details">
          <p>湿度：{{item.rh}}


          </p>
          <p>描述：{{item.text}}</p>
          <p>风级：{{ item.wind_class}}</p>
          <p>风向：{{item.wind_dir}}</p>
          <p>体感温度：{{item.feels_like}}</p>

        </div>
        <div class="week">
          <p>未来气温</p>
          <ul>
            <li>lorem</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
          </ul>
        </div>
      </div>

    </div>




  </main>
</template>

<style lang="scss">
.container {
  width: 100%;
  height: 100vh;
  background-color: #b62020;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  .head {
    width: 100%;
    height: 50px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;

    .left {

      display: flex;

      flex-direction: row;

      .text {
        margin-left: 10px;
        width: 140px;
        color: #fff;
        font-size: 1.2rem;
        font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;

        line-height: 50px;
      }

    }


    .input {
      width: 200px;
      margin: 5px auto;

    }

    el-button {
      margin-right: 20px;
    }
  }

  .main {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;

    .box1 {
      width: 100%;
      height: 15%;
      background-color: aqua;
      display: flex;
      justify-content: space-between;
    }

    .details {
      width: 100%;
      height: 60%;
      background-color: darkgoldenrod;
      display: flex;
      justify-content: space-between;
    }
    .main{
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: space-around;
    }

    .week {
      width: 100%;
      height: 25%;
      background-color: salmon;
      display: flex;
      justify-content: space-around;
    }

  }


}</style>
